package com.niuke;

import com.leetCode.tree.TreeNode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-12-10 10:56:54
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-12-10     张李鑫                     1.0         1.0 Version
 */
public class JZ55 {

    /**
     * 输入一棵二叉树，求该树的深度。从根结点到叶结点依次经过的结点（含根、叶结点）形成树的一条路径，最长路径的长度为树的深度，根节点的深度视为 1 。
     * @param root
     * @return
     */

    public int TreeDepth(TreeNode root) {
        return process(root).height;
    }

    private Info process(TreeNode root) {
        if (root==null){
            return new Info(0);
        }

        Info leftInfo = process(root.left);
        Info rightInfo=process(root.right);

        return new Info(Math.max(leftInfo.height,rightInfo.height)+1);
    }


    public static class Info{
        int height;

        public Info(int height) {
            this.height = height;
        }
    }
}
